import json
import random
from flask import Flask, request
from flask_cors import CORS
import pandas as pd
from tools import *


app = Flask(__name__)
cors = CORS(app, supports_credentials=True,
            resources={r"/getAllData": {"origins": "*"}})


@app.route('/getAllData', methods=['GET', 'POST'])
def get_all_data():
    val = request.get_json()
    print(val)
    if val["first"]:
        return {
            "data": handel_topic_over_time_gps("./data/topic_details/topic_over_time_GPS.csv"),
            "topicHeat": handel_topic_heat("./data/topic_details/topic_heat.csv"),
            "allTopicWordEvolution": handel_topic_word_evolution(
                './data/semantic_evolution/topic_word_evolution/combined_word_evolution.csv',
                "./data/semantic_evolution/topic_word_evolution/combined_word_evolution_bar.csv")
        }
    else:
        return {
            "topicWordEvolution": handel_topic_word_evolution(
                './data/semantic_evolution/topic_word_evolution/topic_{}_word_evolution.csv'.format(val["topic"]),
                "./data/semantic_evolution/topic_word_evolution/topic_{}_word_evolution_bar.csv".format(val["topic"]))
        }


if __name__ == '__main__':
    app.run(debug=True)


